/**
 * Created by win 10 on 11/22/2017.
 */
import Vue from 'vue'
export default{
  // 取参数
  getQueryStringByName: function (name) {
    return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ''])[1].replace(/\+/g, '%20')) || null
  },
  // 设置cookie
  setCookie: function (cname, cvalue, exdays) {
    var d = new Date()
    d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000))
    var expires = 'expires=' + d.toUTCString()
    console.info(cname + '=' + cvalue + '; ' + expires)
    document.cookie = cname + '=' + cvalue + '; ' + expires
    console.info(document.cookie)
  },
  // 获取cookie
  getCookie: function (cname) {
    var name = cname + '='
    var ca = document.cookie.split(';')
    for (var i = 0; i < ca.length; i++) {
      var c = ca[i]
      while (c.charAt(0) === ' ') {
        c = c.substring(1)
      }
      if (c.indexOf(name) !== -1) return c.substring(name.length, c.length)
    }
    return null
  },
  // 清除cookie
  clearCookie: function (cname) {
    this.setCookie(cname, '', -1)
  },
  // 检测cookie
  checkCookie: function (cname) {
    var user = this.getCookie(cname)
    if (user !== '') {
      alert('Welcome again ' + user)
    } else {
      user = prompt('Please enter your name:', '')
      if (user !== '' && user !== null) {
        this.setCookie(cname, user, 365)
      }
    }
  },
  // 域名
  domainName: function () {
    // return 'https://www.juletrip.com'
  },
  hostVaule: function () {
    var hostAdmin = ''
    if (process.env.NODE_ENV === 'development') {
      hostAdmin =  'https://www.juletrip.com'
    }
    return hostAdmin
    // return process.env.NODE_ENV === 'development' ? 'https://www.juletrip.com' : ''
  },
  // 判断是否在微信内
  is_weixin: function (){
    var ua = navigator.userAgent.toLowerCase()
    if (ua.match(/MicroMessenger/i) === 'micromessenger') {
      return true
    } else {
      return false
    }
  }
}
